<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${pageContext.request.contextPath}"/>
<div id="applyDialog" class="container-fluid">
    <div class="row">
        <form id="createForm" method="post" class="form-horizontal" action="">
            <div class="form-group">
                <label class="col-sm-4 control-label">
                    <span class="help-inline"><font color="red">*</font> </span>
                    可提现金额：</label>
                <div class="col-sm-5">
                    <input type="text" readonly class="form-control" value="${billStatistics.amountRateTotal}" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="amount">
                    <span class="help-inline"><font color="red">*</font> </span>
                    金额：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="amount" name="amount" placeholder="金额" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="mode">
                    <span class="help-inline"><font color="red">*</font> </span>
                    提现方式：</label>
                <div class="col-sm-5">
                    <select id="mode" name="mode" class="form-control" placeholder="提现方式">
                        <option value="1" selected="selected">银行卡</option>
                        <option value="2" >支付宝</option>
                        <option value="3" >微信</option>
                    </select>
                </div>
            </div>
            <div class="bank form-group">
                <label class="col-sm-4 control-label" for="bank">
                    <span class="help-inline"><font color="red">*</font> </span>
                    开户行：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="bank" name="bank" placeholder="开户行" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="bankCardNumber">
                    <span class="help-inline"><font color="red">*</font> </span>
                    银行卡号码/支付宝账号/微信账号：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="bankCardNumber" name="bankCardNumber" placeholder="开户行" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="bankUser">
                    <span class="help-inline"><font color="red">*</font> </span>
                    开户人姓名/支付宝昵称/微信昵称：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="bankUser" name="bankUser" placeholder="开户行" />
                </div>
            </div>
            <div class="bank form-group">
                <label class="col-sm-4 control-label" for="bankPhone">
                    <span class="help-inline"><font color="red">*</font> </span>
                    银行预留电话号码：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="bankPhone" name="bankPhone" placeholder="预留电话号码" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="phone">
                    <span class="help-inline"><font color="red">*</font> </span>
                    联系电话号码：</label>
                <div class="col-sm-5">
                    <input type="text" class="form-control" id="phone" name="phone" placeholder="联系电话号码" />
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-4 control-label" for="bz">描述：</label>
                <div class="col-sm-5">
                    <textarea class="form-control" id="bz" name="bz" placeholder="描述"></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8 col-sm-offset-4">
                    <button type="button" class="btn btn-primary" onclick="createSubmit();">
                        保存
                    </button>
                    <button type="button" class="btn btn-default"
                            onclick="applyDialog.close();">取消
                    </button>
                </div>
            </div>
        </form>
    </div>
</div>
<script>

    $(function(){
        $('#mode').change(function() {
            var mode = $(this).val();
            if (mode == 1){
                $('.bank').show();
            } else {
                $('.bank').hide();
            }
        });
    })

    function validateForm(){
        return $( "#createForm" ).validate( {
            rules: {
                amount: "required",
                bank: {
                    required: true,
                    maxlength: 512
                },
                bankCardNumber: {
                    required: true,
                    maxlength: 64
                },
                bankPhone: {
                    required: true,
                    maxlength: 11
                },
                bankUser: {
                    required: true,
                    maxlength: 64
                },
                phone: {
                    required: true,
                    maxlength: 11
                },
                bz: {
                    maxlength: 500
                }
            },
            messages: {
                amount: "该项是必填项。",
                bank: {
                    required: "该项是必填项。",
                    maxlength: "长度超出512个字符。"
                },
                bankCardNumber: {
                    required: "该项是必填项。",
                    maxlength: "长度超出64个字符。"
                },
                bankPhone:{
                    required: "该项是必填项。",
                    maxlength: "长度超出11个字符。"
                },
                bankUser:{
                    required: "该项是必填项。",
                    maxlength: "长度超出64个字符。"
                },
                phone: {
                    required: "该项是必填项。",
                    maxlength: "长度超出64个字符。"
                },
                bz: {
                    maxlength: "描述长度超出500个字符"
                }
            },
            errorElement: "em",
            errorPlacement: function ( error, element ) {
                // Add the `help-block` class to the error element
                error.addClass( "help-block" );

                if ( element.prop( "type" ) === "checkbox" ) {
                    error.insertAfter( element.parent( "label" ) );
                } else {
                    error.insertAfter( element );
                }
            },
            highlight: function ( element, errorClass, validClass ) {
                $( element ).parents( ".col-sm-5" ).addClass( "has-error" ).removeClass( "has-success" );
            },
            unhighlight: function (element, errorClass, validClass) {
                $( element ).parents( ".col-sm-5" ).addClass( "has-success" ).removeClass( "has-error" );
            }
        } );
    }
    //注册表单验证
    $(validateForm());

    function createSubmit() {
        if(validateForm().form()){
            $.ajax({dataType: 'json',
                type: 'post',
                url: '${basePath}/manage/bill/apply/${billStatistics.id}',
                data: $('#createForm').serialize(),
                success: function(result) {
                    if (result.code != 1) {
                        infoDialog(result.data);
                    } else {
                        applyDialog.close();
                        $table.bootstrapTable('refresh');
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    infoDialog(textStatus);
                }
            });
        }
    }
</script>